﻿//----------------------------------------------------------
// Description: Define topic object
// Creater:     linjie 2008-10-25
//----------------------------------------------------------  
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Patent.DBUtility;

namespace Patent.LJ
{
    /// <summary>
    /// ptcase_m Class
    /// </summary>
    public class Topic
    {
        public Topic()
        {
        }

        #region Properity
        /// <summary>
        /// PrimaryKey 
        /// </summary>
        private int _id;

        public int TopicID
        {
            get { return _id; }
            set { _id = value; }
        }


        private string _topicName;
        /// <summary>
        /// 专题名称 
        /// </summary>
        public string TopicName
        {
            get { return _topicName; }
            set { _topicName = value; }
        }

        private string _infoTable;
        /// <summary>
        /// 信息表名 
        /// </summary>
        public string InfoTable
        {
            get { return _infoTable; }
            set { _infoTable = value; }
        }

        private string _inventTable;
        /// <summary>
        /// 发明表名 
        /// </summary>
        public string InvetnTable
        {
            get { return _inventTable; }
            set { _inventTable = value; }
        }

        private string _classificationTable;
        /// <summary>
        /// 分类表名 
        /// </summary>
        public string ClassificationTable
        {
            get { return _classificationTable; }
            set { _classificationTable = value; }
        }

        private string _contractTable;
        /// <summary>
        /// 合作条约表 
        /// </summary>
        public string ContractTable
        {
            get { return _contractTable; }
            set { _contractTable = value; }
        }

        private string _ipcTable;
        /// <summary>
        /// iPC表名 
        /// </summary>
        public string IpcTable
        {
            get { return _ipcTable; }
            set { _ipcTable = value; }
        }

        private string _originalTable;
        /// <summary>
        /// 原产区表 
        /// </summary>
        public string OriginalTable
        {
            get { return _originalTable; }
            set { _originalTable = value; }
        }

        private string _applicationTable;
        /// <summary>
        /// 申请区表 
        /// </summary>
        public string ApplicationTable
        {
            get { return _applicationTable; }
            set { _applicationTable = value; }
        }

        private string _minYear;
        /// <summary>
        /// 最小年份 
        /// </summary>
        public string MinYear
        {
            get { return _minYear; }
            set { _minYear = value; }
        }

        private string _maxYear;
        /// <summary>
        /// 最大年份 
        /// </summary>
        public string MaxYear
        {
            get { return _maxYear; }
            set { _maxYear = value; }
        }

        private string _dataSource;
        /// <summary>
        /// 数据源 
        /// </summary>
        public string DataSource
        {
            get { return _dataSource; }
            set { _dataSource = value; }
        }

        private string _applicationID;
        /// <summary>
        /// 申请号 
        /// </summary>
        public string ApplicationID
        {
            get { return _applicationID; }
            set { _applicationID = value; }
        }

        private string _declareID;
        /// <summary>
        /// 公告号 
        /// </summary>
        public string DeclareID
        {
            get { return _declareID; }
            set { _declareID = value; }
        }

        private string _patentID;
        /// <summary>
        /// 专利号 
        /// </summary>
        public string PatentID
        {
            get { return _patentID; }
            set { _patentID = value; }
        }

        private string _applyStartDate;
        /// <summary>
        /// 申请起日 
        /// </summary>
        public string ApplyStartDate
        {
            get { return _applyStartDate; }
            set { _applyStartDate = value; }
        }

        private string _applyEndDate;
        /// <summary>
        /// 申请止日 
        /// </summary>
        public string ApplyEndDate
        {
            get { return _applyEndDate; }
            set { _applyEndDate = value; }
        }

        private string _declareStartDate;
        /// <summary>
        /// 公告起日 
        /// </summary>
        public string DeclareStartDate
        {
            get { return _declareStartDate; }
            set { _declareStartDate = value; }
        }

        private string _declareEndDate;
        /// <summary>
        /// 公告止日 
        /// </summary>
        public string DeclareEndDate
        {
            get { return _declareEndDate; }
            set { _declareEndDate = value; }
        }

        private string _authorizeStartDate;
        /// <summary>
        /// 授权起日 
        /// </summary>
        public string AuthorizeStartDate
        {
            get { return _authorizeStartDate; }
            set { _authorizeStartDate = value; }
        }

        private string _authorizeEndtDate;
        /// <summary>
        /// 授权止日 
        /// </summary>
        public string AuthorizeEndtDate
        {
            get { return _authorizeEndtDate; }
            set { _authorizeEndtDate = value; }
        }

        private string _inventionName;
        /// <summary>
        /// 发明名称 
        /// </summary>
        public string InventionName
        {
            get { return _inventionName; }
            set { _inventionName = value; }
        }

        private string _inventor;
        /// <summary>
        /// 发明人 
        /// </summary>
        public string Inventor
        {
            get { return _inventor; }
            set { _inventor = value; }
        }

        private string _applicant;
        /// <summary>
        /// 申请人 
        /// </summary>
        public string Applicant
        {
            get { return _applicant; }
            set { _applicant = value; }
        }

        private string _address;
        /// <summary>
        /// 地址 
        /// </summary>
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }

        private string _mainClassification;
        /// <summary>
        /// 主分类 
        /// </summary>
        public string MainClassification
        {
            get { return _mainClassification; }
            set { _mainClassification = value; }
        }

        private string _viceClassification;
        /// <summary>
        /// 副分类 
        /// </summary>
        public string ViceClassification
        {
            get { return _viceClassification; }
            set { _viceClassification = value; }
        }

        private string _claim;
        /// <summary>
        /// 权利要求 
        /// </summary>
        public string Claim
        {
            get { return _claim; }
            set { _claim = value; }
        }

        private string _abstract;
        /// <summary>
        /// 摘要 
        /// </summary>
        public string Abstract
        {
            get { return _abstract; }
            set { _abstract = value; }
        }

        private string _priority;
        /// <summary>
        /// 优先权 
        /// </summary>
        public string Priority
        {
            get { return _priority; }
            set { _priority = value; }
        }

        private string _expression;
        /// <summary>
        /// 表达式 
        /// </summary>
        public string Expression
        {
            get { return _expression; }
            set { _expression = value; }
        }

        private string _createDate;
        /// <summary>
        /// 创建日期 
        /// </summary>
        public string CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }

        private string _creator;
        /// <summary>
        /// 创建人 
        /// </summary>
        public string Creator
        {
            get { return _creator; }
            set { _creator = value; }
        }

        /// <summary>
        /// Datebase Access Class
        /// </summary>
        private SQLHelper helper = new SQLHelper();
        #endregion



        /// <summary>
        /// Add ptcase_m 
        /// </summary>
        public int Add()
        {
            string sql = "insert into ptcase_m(专题名称,信息表名,发明表名,分类表名,合作条约表,IPC表名,原产区表,申请区表,最小年份,最大年份,数据源,申请号,公告号,专利号,申请起日,申请止日,公告起日,公告止日,授权起日,授权止日,发明名称,发明人,申请人,地址,主分类,副分类,权利要求,摘要,优先权,表达式,创建日期,创建人) values (@专题名称,@信息表名,@发明表名,@分类表名,@合作条约表,@ipc表名,@原产区表,@申请区表,@最小年份,@最大年份,@数据源,@申请号,@公告号,@专利号,@申请起日,@申请止日,@公告起日,@公告止日,@授权起日,@授权止日,@发明名称,@发明人,@申请人,@地址,@主分类,@副分类,@权利要求,@摘要,@优先权,@表达式,@创建日期,@创建人)";
            SqlParameter[] parms = new SqlParameter[32];
            parms[0] = helper.CreateInParam("@专题名称", SqlDbType.VarChar, 40, this._topicName);
            parms[1] = helper.CreateInParam("@信息表名", SqlDbType.VarChar, 20, this._infoTable);
            parms[2] = helper.CreateInParam("@发明表名", SqlDbType.VarChar, 20, this._inventTable);
            parms[3] = helper.CreateInParam("@分类表名", SqlDbType.VarChar, 20, this._classificationTable);
            parms[4] = helper.CreateInParam("@合作条约表", SqlDbType.VarChar, 20, this._contractTable);
            parms[5] = helper.CreateInParam("@ipc表名", SqlDbType.VarChar, 20, this._ipcTable);
            parms[6] = helper.CreateInParam("@原产区表", SqlDbType.VarChar, 20, this._originalTable);
            parms[7] = helper.CreateInParam("@申请区表", SqlDbType.VarChar, 20, this._applicationTable);
            parms[8] = helper.CreateInParam("@最小年份", SqlDbType.VarChar, 4, this._minYear);
            parms[9] = helper.CreateInParam("@最大年份", SqlDbType.VarChar, 4, this._maxYear);
            parms[10] = helper.CreateInParam("@数据源", SqlDbType.VarChar, 11, this._dataSource);
            parms[11] = helper.CreateInParam("@申请号", SqlDbType.VarChar, 14, this._applicationID);
            parms[12] = helper.CreateInParam("@公告号", SqlDbType.VarChar, 14, this._declareID);
            parms[13] = helper.CreateInParam("@专利号", SqlDbType.VarChar, 14, this._patentID);
            parms[14] = helper.CreateInParam("@申请起日", SqlDbType.VarChar, 10, this._applyStartDate);
            parms[15] = helper.CreateInParam("@申请止日", SqlDbType.VarChar, 10, this._applyEndDate);
            parms[16] = helper.CreateInParam("@公告起日", SqlDbType.VarChar, 10, this._declareStartDate);
            parms[17] = helper.CreateInParam("@公告止日", SqlDbType.VarChar, 10, this._declareEndDate);
            parms[18] = helper.CreateInParam("@授权起日", SqlDbType.VarChar, 10, this._authorizeStartDate);
            parms[19] = helper.CreateInParam("@授权止日", SqlDbType.VarChar, 10, this._authorizeEndtDate);
            parms[20] = helper.CreateInParam("@发明名称", SqlDbType.VarChar, 80, this._inventionName);
            parms[21] = helper.CreateInParam("@发明人", SqlDbType.VarChar, 60, this._inventor);
            parms[22] = helper.CreateInParam("@申请人", SqlDbType.VarChar, 30, this._applicant);
            parms[23] = helper.CreateInParam("@地址", SqlDbType.VarChar, 100, this._address);
            parms[24] = helper.CreateInParam("@主分类", SqlDbType.VarChar, 12, this._mainClassification);
            parms[25] = helper.CreateInParam("@副分类", SqlDbType.VarChar, 100, this._viceClassification);
            parms[26] = helper.CreateInParam("@权利要求", SqlDbType.VarChar, 4000, this._claim);
            parms[27] = helper.CreateInParam("@摘要", SqlDbType.VarChar, 4000, this._abstract);
            parms[28] = helper.CreateInParam("@优先权", SqlDbType.VarChar, 40, this._priority);
            parms[29] = helper.CreateInParam("@表达式", SqlDbType.VarChar, 4000, this._expression);
            parms[30] = helper.CreateInParam("@创建日期", SqlDbType.VarChar, 10, this._createDate);
            parms[31] = helper.CreateInParam("@创建人", SqlDbType.VarChar, 10, this._creator);

            int result = helper.RunSQL(sql, parms);
            return result;
        }

        /// <summary>
        /// get ptcase_m 
        /// </summary>
        public Topic(int topicID)
        {
            if (topicID == 0)
            {
                return;
            }
            string sql = "select  专题名称,信息表名,发明表名,分类表名,合作条约表,IPC表名,原产区表,申请区表,最小年份,最大年份,数据源,申请号,公告号,专利号,申请起日,申请止日,公告起日,公告止日,授权起日,授权止日,发明名称,发明人,申请人,地址,主分类,副分类,权利要求,摘要,优先权,表达式,创建日期,创建人 from ptcase_m where 专题编号=@专题编号";
            SqlParameter[] parms = new SqlParameter[1];
            parms[0] = helper.CreateInParam("@专题编号", SqlDbType.Int, 0, topicID);
            SqlDataReader reader;
            helper.RunSQL(sql, parms, out reader);
            if (reader.HasRows)
            {
                _id = topicID;
                reader.Read();
                
                if (!reader.IsDBNull(0)) _topicName = reader.GetString(0);
                if (!reader.IsDBNull(1)) _infoTable = reader.GetString(1);
                if (!reader.IsDBNull(2)) _inventTable = reader.GetString(2);
                if (!reader.IsDBNull(3)) _classificationTable = reader.GetString(3);
                if (!reader.IsDBNull(4)) _contractTable = reader.GetString(4);
                if (!reader.IsDBNull(5)) _ipcTable = reader.GetString(5);
                if (!reader.IsDBNull(6)) _originalTable = reader.GetString(6);
                if (!reader.IsDBNull(7)) _applicationTable = reader.GetString(7);
                if (!reader.IsDBNull(8)) _minYear = reader.GetString(8);
                if (!reader.IsDBNull(9)) _maxYear = reader.GetString(9);
                if (!reader.IsDBNull(10)) _dataSource = reader.GetString(10);
                if (!reader.IsDBNull(11)) _applicationID = reader.GetString(11);
                if (!reader.IsDBNull(12)) _declareID = reader.GetString(12);
                if (!reader.IsDBNull(13)) _patentID = reader.GetString(13);
                if (!reader.IsDBNull(14)) _applyStartDate = reader.GetString(14);
                if (!reader.IsDBNull(15)) _applyEndDate = reader.GetString(15);
                if (!reader.IsDBNull(16)) _declareStartDate = reader.GetString(16);
                if (!reader.IsDBNull(17)) _declareEndDate = reader.GetString(17);
                if (!reader.IsDBNull(18)) _authorizeStartDate = reader.GetString(18);
                if (!reader.IsDBNull(19)) _authorizeEndtDate = reader.GetString(19);
                if (!reader.IsDBNull(20)) _inventionName = reader.GetString(20);
                if (!reader.IsDBNull(21)) _inventor = reader.GetString(21);
                if (!reader.IsDBNull(22)) _applicant = reader.GetString(22);
                if (!reader.IsDBNull(23)) _address = reader.GetString(23);
                if (!reader.IsDBNull(24)) _mainClassification = reader.GetString(24);
                if (!reader.IsDBNull(25)) _viceClassification = reader.GetString(25);
                if (!reader.IsDBNull(26)) _claim = reader.GetString(26);
                if (!reader.IsDBNull(27)) _abstract = reader.GetString(27);
                if (!reader.IsDBNull(28)) _priority = reader.GetString(28);
                if (!reader.IsDBNull(29)) _expression = reader.GetString(29);
                if (!reader.IsDBNull(30)) _createDate = reader.GetString(30);
                if (!reader.IsDBNull(31)) _creator = reader.GetString(31);
                reader.Close();
                
            }
            reader.Close();
        }



        /// <summary>
        /// delete ptcase_m 
        /// </summary>
        /// <returns></returns>
        public int Delete()
        {
            string sql = "delete from ptcase_m where 专题编号=@id";
            SqlParameter[] parms = new SqlParameter[1];
            parms[0] = helper.CreateInParam("@id", SqlDbType.Int, 0, this._id);
            int result = helper.RunSQL(sql, parms);
            return result;
        }


    }


    public class PtCaseM
    {
        public static List<Topic> GetAll(string creator)
        {
            if (string.IsNullOrEmpty(creator))
            {
                return null;
            }

            SQLHelper helper = new SQLHelper();
            string sql = "select 专题编号 from ptcase_m where 创建人=@creator";
            SqlParameter[] parms = new SqlParameter[1];
            parms[0] = helper.CreateInParam("@creator", SqlDbType.VarChar, 10, creator);
            SqlDataReader reader;

            helper.RunSQL(sql, parms, out reader);
            List<Topic> allTopics = new List<Topic>();
            if (reader.HasRows)
            {
                int rowCount = 0;
                while (reader.Read())
                {
                    int topicID = 0;
                    if (!reader.IsDBNull(0)) topicID = reader.GetInt32(0);
                    Topic topic = new Topic(topicID);
                    if (topic.TopicID == 0)
                    {
                        continue;
                    }
                    allTopics.Add(topic);
                    rowCount++;
                }
            }
            else
            {
                return null;
            }
            
            return  allTopics;
        }
    }
}
